class Solution {
public:
    vector<int> canSeePersonsCount(vector<int>& heights) {
        int n=heights.size();
        vector<int>a(n,0);
        stack<int>st;
        for(int i=n-1;i>=0;i--){
            int h=heights[i];
            while(!st.empty()&&heights[st.top()]<=h){
                st.pop();
                a[i]+=1;
            }
            if(!st.empty()){
                a[i]+=1;
            }
            st.push(i);
        }
        return a;
    }
};
